package com.zy.controller;

import com.zy.crypto.BASE64Coding;
import com.zy.model.sys.ZyRole;
import com.zy.model.sys.ZyUser;
import com.zy.model.sys.ZyUserExample;
import com.zy.resp.ZyResult;
import com.zy.service.sys.ZyRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 2018/4/27 10:30
 * 角色控制类
 * ly
 */
@Controller
@RequestMapping("/api/role")
public class ZyRoleController {
    @Autowired
    private ZyRoleService roleService;

 /*   @ResponseBody
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String  addRole(HttpServletRequest request, HttpServletResponse response,
                           @RequestBody ZyRole role){
        ZyRole  zyRole=new ZyRole();
        zyRole.setName(role.getName());
        return ZyResult.success("ok");
    }


    @ResponseBody
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String  updateUser(HttpServletRequest  request, HttpServletResponse response,
                              @RequestBody ZyUser user){
        ZyUser zyUser=new ZyUser();
        zyUser.setAccount(user.getAccount());
        zyUser.setId(user.getId());
        zyUser.setPassword(BASE64Coding.encode(user.getPassword()));
        zyUser.setCreateBy(0L);
        zyUser.setUpdateBy(0L);
        zyUser.setUpdateDate(new Date());
        zyUser.setLogintime(new Date());
        userService.updateByPrimaryKeySelective(zyUser);
        return ZyResult.success("ok");
    }


    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public String  deleteUser(HttpServletRequest  request, HttpServletResponse response,
                              long id ){
        userService.deleteByPrimaryKey(id);
        return ZyResult.success("ok");
    }



    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String  listUser(HttpServletRequest  request, HttpServletResponse response,
                            int pageNo,int pageSize){
        ZyUserExample userExample=new ZyUserExample();
        List<ZyUser> userList=userService.selectByExampleWithBLOBsForStartPage(userExample,pageNo,pageSize);
        return ZyResult.success(userList);
    }*/
}
